package com.xiaoxi.abstractfactorymode.factory;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName IPage
 * @Description 生成页面
 * @Author xiaoxi
 * @Date 2023/3/12 21:28
 * @Version 1.0
 */
public abstract class IPage implements HTML {

    protected String title;
    protected String author;
    protected List<IItem> iItemList = new ArrayList<>();

    public IPage(String title, String author) {
        this.title = title;
        this.author = author;
    }

    public void add(IItem iItem) {
        iItemList.add(iItem);
    }

    public void output() {
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(title + ".html");
            fileOutputStream.write(makeHTML().getBytes(StandardCharsets.UTF_8));
            fileOutputStream.close();
        } catch (IOException e) {
            System.out.println("出现异常：" + e.getMessage());
        }
    }

}
